#!/bin/bash

SSH_OPTS='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'

HOST=
KEY=
NSHOST=

JAR=camid3-0.3.1-SNAPSHOT-jar-with-dependencies.jar

MAIN=

while test -n "$1" ; do
	case $1 in
		-host)
			shift
			HOST=$1
			shift
			;;
		-key)
			shift
			KEY=$1
			shift
			;;
		-main)
			MAIN=1
			shift
			;;
		-nshost)
			shift
			NSHOST=$1
			shift
			;;
	esac
done

MID_OPTS=

if [ $MAIN -eq 1 ] ; then
	MID_OPTS="-ns -cm"
else
	MID_OPTS="-nshost $NSHOST -nsport 15001"
fi

TARGET_LOCATION=/home/ubuntu


ssh $SSH_OPTS -i $KEY ubuntu@$HOST "nohup java -jar $TARGET_LOCATION/$JAR -port 15001 $MID_OPTS 2> $TARGET_LOCATION/out.log > $TARGET_LOCATION/out.log < /dev/null &"


